package com.shekhar.shortnotes.service;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.shekhar.shortnotes.domain.Note;
import com.shekhar.shortnotes.domain.Notebook;


public class NotebookServiceImpl implements NotebookService {
    
    @Autowired
    private MongoTemplate mongoTemplate;
    
    public void pushNotesToNotebook(ObjectId notebookId, Note note){
        mongoTemplate.updateFirst(new Query(Criteria.where("_id").is(notebookId)), new Update().push("notes", note), Notebook.class);
    }
}
